from django.db.models import QuerySet
from datetime import datetime
from server.apps.todo.logic.jobs.validation import ValidTodoData
from server.apps.todo.models import ToDo


def create(valid_data: ValidTodoData) -> ToDo:
    """
    Creates a new job.
    """
    return ToDo.objects.create(
        title=valid_data.title,
        description=valid_data.description,
        done=valid_data.done,
    )


def edit(job_id, valid_data: ValidTodoData) -> ToDo:
    """
    Edit the job.
    """
    return ToDo.objects.filter(id=job_id).update(
        title=valid_data.title,
        description=valid_data.description,
        done=valid_data.done,
        updated_at=datetime.now()
    )


def done(job_id) -> ToDo:
    """
    Done the job.
    """
    return ToDo.objects.filter(id=job_id).update(
        done=bool(True),
        updated_at=datetime.now()
    )


def delete(job_id) -> ToDo:
    """
    Delete the job.
    """
    return ToDo.objects.filter(id=job_id).delete()

